package iterator;

/**
 * 迭代器实现类
 **/
public class MyIterator<T> implements IIterator<T> {

	private ICollection<T> collection;
	private int index = 0;

	public MyIterator(ICollection<T> collection) {

		this.collection = collection;
	}

	@Override
	public boolean hasNext() {

		return index < this.collection.size();
	}

	@Override
	public boolean hasPrevious() {

		return index > 0;
	}

	@Override
	public T next() {

		return this.collection.get(index++);
	}

	@Override
	public T previous() {

		return this.collection.get(index--);
	}

}
